package com.augurit.common.sysconfig.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.entity.SysConfig;
import com.augurit.common.sysconfig.web.form.SysConfigForm;
import com.augurit.common.system.util.OrgUtils;

public class SysConfigConvertor {
	
	public static SysConfigForm convertVoToForm(SysConfig entity) {
		if(entity != null) {
			SysConfigForm form = new SysConfigForm();
			form.setId(entity.getId());
			form.setKey(entity.getKey());
			form.setValue(OrgUtils.convertToBooleanStr(entity.getValue()));
			form.setMemo(entity.getMemo());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(SysConfigForm form, SysConfig entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getKey() != null && form.getKey().trim().length() > 0)
				entity.setKey(form.getKey().trim());
			if(form.getValue() != null && form.getValue().trim().length() > 0)
				entity.setValue(form.getValue().trim());
			if(form.getMemo() != null && form.getMemo().trim().length() > 0)
				entity.setMemo(form.getMemo().trim());
		}
	}
	
	public static List<SysConfigForm> convertVoListToFormList(List<SysConfig> sysConfigList) {
		if(sysConfigList != null && sysConfigList.size() > 0) {
			List<SysConfigForm> sysConfigFormList = new ArrayList();
			for(int i=0; i<sysConfigList.size(); i++) {
				sysConfigFormList.add(convertVoToForm(sysConfigList.get(i)));
			}
			return sysConfigFormList;
		}
		return null;
	}
	
	public static List<SysConfig> convertFormListToVoList(List<SysConfigForm> sysConfigFormList) {
		if(sysConfigFormList != null && sysConfigFormList.size() > 0) {
			List<SysConfig> sysConfigList = new ArrayList();
			for(int i=0; i<sysConfigFormList.size(); i++) {
				SysConfig sysConfig = new SysConfig();
				convertFormToVo(sysConfigFormList.get(i), sysConfig);
				sysConfigList.add(sysConfig);
			}
			return sysConfigList;
		}
		return null;
	}
}